﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using SCRUM.Core.Configuration;

namespace SCRUM.Core.BusinessObjects
{
    /// <summary>
    /// Business object which holds following information:
    ///  * ID - object's unique identifier (among objects of same type)
    ///  * Name - name of object
    ///  * Estimation - estimation of total work on object
    ///  * Progress - progress of total work on object (in%)
    ///  * LastChange - date of last changes made to object
    ///  * Description - description of object
    ///  * StateID - identifier of state
    /// </summary>
    [Serializable()]
    public abstract class DescriptedBusinessObject : HierarchicalBusinessObject
    {
        /// <summary>
        /// Gets or sets the description of object.
        /// </summary>
        /// <value>The description.</value>
        public string Description { get; set; }

        /// <summary>
        /// Gets or sets the state ID.
        /// </summary>
        /// <value>The state ID.</value>
        public int StateID { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="DescriptedBusinessObject"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="name">The name.</param>
        /// <param name="description">The description.</param>
        /// <param name="estimation">The estimation.</param>
        /// <param name="progress">The progress.</param>
        /// <param name="change">The change.</param>
        protected DescriptedBusinessObject(int id, string name, string description, double estimation, double progress, DateTime change, int stateID)
            : base(id, name, estimation, progress, change)
        {
            this.Description = description;
            this.StateID = stateID;
        }

        /// <summary>
        /// Gets or sets the short (first xx characters) description.
        /// </summary>
        /// <value>The short description.</value>
        public string ShortDescription
        {
            get
            {
                return ShortenText(this.Description);
            }
        }

        /// <summary>
        /// Gets the state.
        /// </summary>
        /// <value>The state.</value>
        public State State
        {
            get
            {
                if (state == null)
                {
                    state = DAO.DAOState.GetStateForType(this.StateID, this.stateType);
                }
                return state;
            }
            set
            {
                this.state = value;
            }
        }

        /// <summary>
        /// type of state
        /// </summary>
        protected State.StateTypes stateType;

        /// <summary>
        /// Private representation of state
        /// </summary>
        private State state;
    }


}
